import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_swiper/flutter_swiper.dart';
import '../../widget/page_indicator.dart';
import '../../widget/my_image.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

//首页轮播图
class HomeBanner extends StatefulWidget {
  final List<dynamic> homeBanner;

  HomeBanner({this.homeBanner});

  @override
  _HomeBannerState createState() => _HomeBannerState();
}

class _HomeBannerState extends State<HomeBanner> {
  @override
  Widget build(BuildContext context) {
    return Container(
      width: double.infinity,
      height: 300.w,
      decoration: BoxDecoration(
        color: Colors.red,
      ),
      child: Stack(children: <Widget>[
        Positioned(
          bottom: 0,
          left: 25.w,
          child: Container(
            height: 80,
            width: 700.w,
            decoration: BoxDecoration(
              color: Colors.white,
              borderRadius: BorderRadius.only(
                  topLeft: Radius.circular(30), topRight: Radius.circular(30)),
            ),
          ),
        ),
        Positioned(
            top: -2.w,
            left: 80.w,
            width: 600.w,
            height: 250.w,
            child: ClipRRect(
              borderRadius: BorderRadius.circular(20),
              child: AspectRatio(
                aspectRatio: 2 / 1,
                child: Swiper(
                  autoplayDelay: 50000,
                  autoplay: false,
                  itemBuilder: (BuildContext context, int index) {
                    return Container(
                      decoration: BoxDecoration(
                          borderRadius: BorderRadius.all(Radius.circular(30))),
                      child: MyImage(
                        imgSrc: "${widget.homeBanner[index]['pic']}",
                      ),
                    );
                  },
                  itemCount: widget.homeBanner.length,
                  pagination: new SwiperPagination(
                      alignment: Alignment.bottomCenter,
                      builder: new SwiperCustomPagination(builder:
                          (BuildContext context, SwiperPluginConfig config) {
                        return new PageIndicator(
                          layout: PageIndicatorLayout.NIO,
                          size: 10.0,
                          space: 15.0,
                          count: widget.homeBanner.length,
                          controller: config.pageController,
                        );
                      })),
                ),
              ),
            ))
      ]),
    );
  }
}
